package com.tql;

import redis.clients.jedis.Jedis;

public class TestList {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        jedis.flushDB();
        System.out.println("添加list.....................");
        System.out.println("各种列表，比如twitter的关注列表、粉丝列表等，最新消息排行、每篇文章的评论等也可以用Redis的list结构来实现。");
        jedis.lpush("collection","hisir","hisr1","mylove");
        jedis.lpush("key1","hisir","value1","喜欢多云的季节","hisir","hisir");
        jedis.lpush("key2","monkey");
        //list 链式结构
        //获取区间范围内的值
        System.out.println("collection的内容"+jedis.lrange("collection",0,-1));
        System.out.println("key1部分的值"+jedis.lrange("key1",0,2));
        System.out.println("删除指定的值"+jedis.lrem("key1",2,"hisir"));
        System.out.println("查看key1的值"+jedis.lrange("key1",0,-1));
        System.out.println("删除下表0-2区间之外的数"+jedis.ltrim("key1",0,2));
        System.out.println("查看key1的值"+jedis.lrange("key1",0,-1));
        System.out.println("追加数据"+jedis.rpush("key1","喜欢星星的眼泪","hello"));
        System.out.println("查看数据"+jedis.lrange("key1",0,-1));
        System.out.println("key1左端列表出栈"+jedis.lpop("key1"));
        System.out.println("查看数据"+jedis.lrange("key1",0,-1));
        System.out.println("key1右端出栈"+jedis.rpop("key1"));
        System.out.println("查看数据"+jedis.lrange("key1",0,-1));
        System.out.println("修改指定下标的值"+jedis.lset("key1",0,"喜欢多云的季节"));
        System.out.println("查看"+jedis.lrange("key1",0,-1));
        System.out.println("查看key1的长度"+jedis.llen("key1"));
        System.out.println("获取指定下标的元素"+jedis.lindex("key1",0));
        jedis.flushDB();
        System.out.println("查看"+jedis.lrange("key1",0,-1));
        jedis.lpush("key1","3","5","2","-8");
        System.out.println("排序前"+jedis.lrange("key1",0,-1));
        System.out.println("排序后"+jedis.sort("key1"));
    }
}